#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/12/21 21:27
# @Author: hekang
# @Email: 591785757@qq.com
# @File：finance_add_page.py
"""
财务添加应收款页
"""
from selenium.webdriver.common.by import By
from pages.base_page import BasePage


class FinanceAdd(BasePage):
    # 定位器
    cancel_locator = (  # 定位"取消"
        By.XPATH, "/html/body/div[5]/div[2]/div/form/table/thead/tr/td[2]/input[3]")
    name_locator = (  # 定位"应收款名"
        By.ID, "name")
    contract_locator = (  # 定位"合同"
        By.NAME, "contract_name")
    radio_locator = (  # 定位"圆点"
        By.XPATH, "/html/body/div[8]/div[2]/table/tbody[2]/tr/td[1]/input")
    ok_locator = (  # 定位"ok"
        By.CSS_SELECTOR, "body > div:nth-child(9) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > "
                         "div > button:nth-child(1)")
    time_locator = (  # 定位"收款时间"
        By.ID, "pay_time")
    days_locator = (  # 定位"日期选择"
        By.XPATH, "/html/body/div/div[3]/table/tbody/tr[7]/td[5]")
    descript_locator = (  # 定位"描述"
        By.CLASS_NAME, "span6")
    sava_locator = (  # 定位"保存"
        By.CSS_SELECTOR, "body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > "
                         "input:nth-child(1)")

    # 点击"取消"
    def cancel(self):
        self.driver.find_element(*self.cancel_locator).click()

    # 输入"应收款名"
    def add_name(self, name):
        self.driver.find_element(*self.name_locator).send_keys(name)

    # 点击"合同"
    def add_contract(self):
        self.driver.find_element(*self.contract_locator).click()

    # 点击"圆点"
    def add_radio(self):
        self.driver.find_element(*self.radio_locator).click()

    # 点击"圆点"
    def add_ok(self):
        self.driver.find_element(*self.ok_locator).click()

    # 点击"收款时间"
    def add_time(self):
        self.driver.find_element(*self.ok_locator).click()

    # 选择"日期"
    def add_day(self):
        self.driver.switch_to.frame(0)
        self.driver.find_element(*self.days_locator).click()
        self.driver.switch_to.parent_frame()

    # 输入"描述"
    def add_descript(self, descript):
        self.driver.find_element(*self.descript_locator).send_keys(descript)

    # 点击"保存"
    def add_save(self):
        self.driver.find_element(*self.sava_locator).click()
